﻿<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="/loginfonts/iconfont.css">
    <link rel="stylesheet" href="/css/login.css">
    <link rel="stylesheet" href="/css/bootstrap.css">
    <script type="text/javascript" src="/lib/jquery/jquery.1.10.2.js"></script>
    <script type="text/javascript" src="/lib/jquery/jquery.cookie.min.js"></script>

    <script type="text/javascript" src="/js/base.min.js"></script>
    <script type="text/javascript" src="/js/ui.min.js"></script>
    <script type="text/javascript" src="/js/util.min.js"></script>
    <title class="gettext">易付宝</title>
</head>
<body class="login-wbg" id="login">
    <!--login-wrap start-->
    <section class="login-wrap">
        <div class="login-tit"><img alt="logo" src="images/logo.png"></div>
        <div class="login-cont">
            <ul class="login-ul">
                <li>
                    <input name="account" type="text" placeholder="用户名">
                    <label class="iconfont icon-user"></label>
                </li>
                <li>
                    <input name="password" type="password" placeholder="密码">
                    <label class="iconfont icon-key"></label>
                </li>
                <li>
                     <button class="btn" onclick="return login()">登录</button>
                </li>
            </ul>
        </div>
    </section>
    <!--login-wrap end-->
    <script type="text/javascript">

        function login() {
            var data = {
                "account": $("input[name='account']").val(),
                "password": $("input[name='password']").val()
            };

            var cover = FlashPay.UI.Mask({
                obj: $("#login"),
                opacity: 0.5
            });

            $.post("/account/Login", data, function (a) {
                if (a.success) {
                    var username = a.data.userName;
                    var isLogged = a.data.uLoggedIn;
                    var isShowQR = a.data.uShowQR;
                    if (isLogged == 1) {
                        var key = a.data.uSecretKey;
                        var userid = a.data.userId;
                        var height = 340;
                        if (isShowQR == 1) height = 80;
                        var url = "/secondlogin.html?username=" + username + "&secret=" + key + "&isLogged=" + isLogged + "&isShowQR=" + isShowQR + "&userId=" + userid;
                        FlashPay.UI.DialogOpen(encodeURI(url), {
                            title: "验证动态口令",
                            width: 500,
                            height: height,
                            init: function () {
                                this.button(
                                    {
                                        name: "保存",
                                        callback: function () {
                                            var iframe = this.iframe.contentWindow;
                                            if (!iframe.document.body) {
                                                return false;
                                            }
                                            iframe.save();
                                            return false;
                                        },
                                        focus: true,
                                    },
                                    {
                                        name: '取消'
                                    }
                                );
                            }
                        });
                    } else {
                        $.removeCookie('username'); $.removeCookie('companyname'); $.removeCookie('token'); $.removeCookie('language');
                        FlashPay.UI.Tip_success("登录成功！");
                        $.cookie('username', username); $.cookie('companyname', a.data.companyName); $.cookie('token', a.data.token); $.cookie('language', data.language); $.removeCookie('popups');
                        window.location.href = "/index.html";
                    }
                } else {
                    FlashPay.UI.Tip_danger(a.errorMessage);
                }
                cover.Remove();
            });
        }

        $(document).keyup(function (event) {
            var keycode = event.which;
            if (keycode == 13) {
                login();
            }
        });

        $(function () {
            FlashPay.Util.Ajax({
                type: "Get",
                url: "/Account/CheckLogin",
                success: function (res) {
                    if (res.success) {
                        top.location.href = "/index.html";
                    } else {
                        $.removeCookie('username'); $.removeCookie('companyname'); $.removeCookie('token'); $.removeCookie('language');
                    }
                }
            });

            $("select[name='language']").change(function () {
                /* 設定一開始以哪個語系呈現 */
                $.i18n.setLocale($(this).val());

                /* 根據使用者目前語系更改文字內容，動態載入語系檔 */
                $._.replaceByLocale("/js/language/" + $._.getLocale() + ".json");
            });
        })
    </script>
</body>
</html>